package com.hzqy.web.ac.epg;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hzqy.commons.utils.ExcelUtil;
import com.hzqy.commons.utils.ExcelUtil.MyEntry;
import com.hzqy.service.epg.HappyServiceBean;
import com.hzqy.web.vo.CmContentVo;

@Controller
@RequestMapping("/")
public class HappyAction {
	protected final Logger LOG = LoggerFactory.getLogger(getClass());
	@Resource
	private HappyServiceBean happyService;
	
	@RequestMapping(value="/hp/happy_list")
	@ResponseBody
	public Object selectHappyList(CmContentVo ccv,int page, int rows,HttpSession session) {
		Map<String,Object> map = new HashMap<String,Object>();
		map = happyService.selectHappyList(ccv,page,rows);
		return map;
	}
	@RequestMapping(value="/hp/insertVoteUser")
	@ResponseBody
	public Object insertVoteUser(String contentid,int votenum) {
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("f_avu_contentid", contentid);
		map.put("f_avu_votenum", votenum);
		map.put("f_avu_serverid", "123");
		map.put("f_avu_activityid", "44");
		map.put("f_avu_source", "0");
		map.put("f_avu_type", "2");
		map.put("f_avu_memo", "add");
		map.put("f_avu_obligate1", "0");
		return happyService.insertVoteUser(map);
	}
	/**
	 * 审核上线
	 * @param fccid
	 * @return
	 */
	@RequestMapping(value="/hp/updateContenStatus")
	@ResponseBody
	public Object updateContenStatus(int fccid) {
		return happyService.updateContenStatus(fccid);
	}
	/**
	 * 审核失败
	 * @param fccid
	 * @return
	 */
	@RequestMapping(value="/hp/ContenStatusNo")
	@ResponseBody
	public Object ContenStatusNo(int fccid,String f_cc_remark) {
		return happyService.ContenStatusNo(fccid,f_cc_remark);
	}
	
	/**
	 * 下线
	 * @param fccid
	 * @return
	 */
	@RequestMapping(value="/hp/deleteContenStatus")
	@ResponseBody
	public Object deleteContenStatus(int fccid) {
		return happyService.deleteContenStatus(fccid);
	}
	
	@RequestMapping(value="/hp/happy_excel_list")
	@ResponseBody
	public void billExcelList(CmContentVo ccv,HttpServletResponse response)throws IOException {
		Map<String,Object> ExcelListMap = new HashMap<String, Object>();
		
		ExcelListMap =  happyService.selectHappyListExcel(ccv);
		List<CmContentVo> list=new ArrayList<CmContentVo>();
		list = (List<CmContentVo>)ExcelListMap.get("rows");
		List<MyEntry<String, String>> excelCpHeader=new ArrayList<MyEntry<String, String>>();
		excelCpHeader.add(new MyEntry<String,String>("f_cc_name","姓名"));
		excelCpHeader.add(new MyEntry<String,String>("f_cc_code","参赛编号"));
		excelCpHeader.add(new MyEntry<String,String>("roleId","总票数"));
		excelCpHeader.add(new MyEntry<String,String>("f_cc_seriescount","年龄"));
		excelCpHeader.add(new MyEntry<String,String>("f_cc_director","地区"));
		excelCpHeader.add(new MyEntry<String,String>("f_cc_desc","参赛宣言"));
		excelCpHeader.add(new MyEntry<String,String>("f_cc_obligate1","报名时间"));
		excelCpHeader.add(new MyEntry<String,String>("sctt_startDate","创建时间"));
		excelCpHeader.add(new MyEntry<String,String>("sctt_endDate","审核时间"));
		excelCpHeader.add(new MyEntry<String,String>("f_cc_onlinedate","投票截止时间"));
		boolean flag=ExcelUtil.generateExcel(list, excelCpHeader, response);
	}

}
